<template>
  <div class="box">
    <el-form
      :model="Form"
      :rules="rules"
      ref="Form"
      label-width="100px"
      class="demo-ruleForm"
    >
      <h2>系统登录</h2>
      <el-form-item
        label="*用户名"
        prop="username"
        style="margin-right: 20px"
      >
        <el-input type="text" v-model="Form.username"></el-input>
      </el-form-item>
      <el-form-item label="*密码" prop="password">
        <el-input type="password" v-model="Form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import Cookie from 'js-cookie'
// import Mock from 'mockjs'
import {getMenu} from '../api'
export default{
    name:'MyLogain',
   data() {
      return {
        rules:{
username:[
  {required:true,message:'用户名不能为空',trigger:'blur'},
  {min:3,max:8,message:'长度3到6之间',trigger:'blur'}
  ],
  password:[
  {required:true,message:'密码不能为空',trigger:'blur'},
  {min:5,max:15,message:'长度3到6之间',trigger:'blur'}
  ]
        },
Form:{
    username:'',
    password:''
}   
      }
   },
   methods:{
    submitForm(){
// const token=Mock.Random.guid()
 this.$refs.Form.validate((valid)=>{
  if(valid)
  {
    getMenu(this.Form).then(({data})=>{
      console.log(data)
      if(data.code===20000)
      {
        Cookie.set('token',data.data.token)
        this.$store.commit('setmenu',data.data.menu)
        this.$store.commit('addmenu',this.$router)
        this.$router.push('/home')
      }
     else{
      this.$message.error(data.data.message);
     } 
    }
    )
  }
 })
// Cookie.set('token',token)
// this.$router.push('/home')
    },
   },
}
</script>
<style lang="css" scoped>
h2 {
  text-align: center;
  color: #6a6a6a;
  font-size: 18px;
}
.demo-ruleForm {
  width: 400px;
  border: 1px solid #f1f1f1;
  border-radius: 15px;
}
.el-input {
  width: 250px;
}
.el-form-item__content {
  margin-bottom: 20px;
}
::v-deep .el-form-item__label {
  padding-right: 30px;
}
form {
  margin: 200px auto;
}
.el-button {
  margin-left: 63px;
}
.box{
 height: 100vh;	/* 重点一 */
 background-image: url(../images/02.jpg);
 background-repeat: no-repeat;
 background-size: cover; /* 重点二 */
 overflow: auto;
}
</style>
